#include "test.h"
#include "zab_communication.h"
#include "arpa/inet.h"

static void test_pktz_handler(ZAB_PACKET_T* packet, void* user_data)
{
    // nothing
    (void)user_data;
    printf("Received packet: type=%d, size=%d\n", ntohs(packet->type), ntohl(packet->length));
}

void test_packetizer()
{
    ZAB_PACKETIZER_T pktz;
    int i;

    zab_packetizer_init(&pktz, test_pktz_handler, NULL);
    for (i = 0; i < 10; i++)
    {
        int j;
        // type
        zab_packetizer_push_byte(&pktz, 0);
        zab_packetizer_push_byte(&pktz, i);
        // length
        zab_packetizer_push_byte(&pktz, 0);
        zab_packetizer_push_byte(&pktz, 0);
        zab_packetizer_push_byte(&pktz, 0);
        zab_packetizer_push_byte(&pktz, i + 6);
        // data
        for (j = 0; j < i; j++)
            zab_packetizer_push_byte(&pktz, j);
    }
}
